<template>
  <div v-loading="loading" class="app-container">
    <div class="search-box">
      <div class="search-form">
        <el-form ref="searchForm" :inline="true" :model="searchForm">
          <el-form-item label="导入名称" prop="name">
            <el-input v-model="searchForm.name" maxlength="100" autocomplete="off" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="onSearch">查询</el-button>
            <el-button icon="el-icon-remove-outline" title="重置" @click="resetSearchForm" />
          </el-form-item>
        </el-form>
      </div>
    </div>

    <el-table
      ref="multipleTable"
      stripe
      :data="tableData"
      border
      class="table"
    >
      <el-table-column prop="name" label="导入名称" />
      <el-table-column prop="count" label="总记录数" />
      <el-table-column prop="success" label="成功" />
      <el-table-column prop="failure" label="失败" />
      <el-table-column prop="startTime" label="开始时间">
        <template slot-scope="scope">
          <span>{{ scope.row.startTime | parseTime("{y}-{m}-{d} {h}:{i}") }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="finishTime" label="结束时间">
        <template slot-scope="scope">
          <span>{{ scope.row.finishTime | parseTime("{y}-{m}-{d} {h}:{i}") }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="statusName" label="状态" />
      <el-table-column prop="operatorName" label="操作人" />
      <el-table-column prop="message" label="提示信息" />
      <el-table-column prop="resultFile" label="失败记录文件">
        <template slot-scope="scope">
          <a v-if="scope.row.resultFile && scope.row.resultFile.length>0" :href="scope.row.resultFile" target="_blank" style="color:blue;">下载</a>
        </template>
      </el-table-column>
    </el-table>
    <pagination :total="total" :page.sync="curPage" :limit.sync="limit" @pagination="getList" />
  </div>
</template>

<script>
import request from '@/utils/request'
import Pagination from '@/components/Pagination'

export default {
  name: 'ImpResult',
  components: { Pagination },
  data() {
    return {
      curPage: 1,
      limit: 5,
      total: 0,
      loading: true,
      orderByClause: null,
      tableData: [],
      searchForm: {
        name: ''
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 获取数据
    getList() {
      this.loading = true
      const param = {}
      const queryPage = {}
      queryPage.limit = this.limit
      queryPage.offset = this.limit * (this.curPage - 1)
      param.page = queryPage
      if (this.orderByClause && this.orderByClause.trim() !== '') {
        param.orderByClause = this.orderByClause
      }
      this.copyNotBlankField(this.searchForm, param)
      request({ url: '/sys/impresult/findPage', method: 'post', data: param })
        .then(res => {
          this.loading = false
          this.tableData = res.rows
          this.total = res.total
          this.curPage = res.pageNumber
        })
        .catch(e => {
          this.loading = false
          this.$message.error('查询出错')
        })
    },
    onSearch() {
      this.getList()
    },
    resetSearchForm() {
      this.$refs['searchForm'].resetFields()
    }

  }
}
</script>
